package com.giw.project.graph;

import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class GraphGeneratorApp extends Configured implements Tool{
	public int run(String[] args) throws Exception{
		Job job = new Job(getConf());
		job.setJobName("Graph_Generator");
		job.setJarByClass(GraphGeneratorMapper.class);		
		job.setMapperClass(GraphGeneratorMapper.class); 
		job.setReducerClass(GraphGeneratorReducer.class);
		job.setOutputKeyClass(Text.class); 
		job.setOutputValueClass(Text.class);
		job.setInputFormatClass(TextInputFormat.class);
		job.setOutputFormatClass(TextOutputFormat.class);
		FileInputFormat.addInputPath(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		
		boolean success = job.waitForCompletion(true);
		return success ? 0 : 1;
	}
	
	public static void main(String[] args) throws Exception { 
		if (args.length != 2) {
			System.err.println("Usage: <input path> <output path>"); 
			System.exit(-1);
		}
		int ret = ToolRunner.run(new GraphGeneratorApp(), args);
		System.exit(ret);
	}

}
